<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
  <script src="../js/vue.js"></script>
</head>

<body>
  <div id="app">
    <input v-mymodel="username" type="text"></input><br>
    <input v-mymodel="password" type="text" type="text">
    {{username}} {{password}}
  </div>
  <script>
    Vue.directive('mymodel', {
      bind(el, binding, vNode, oldNode) {
        console.log(el, binding, vNode, oldNode);
        console.log('bind');
        // 双向数据绑定线路一：将数据模型中的数据赋值给dom节点的vlaue
        el.value = binding.value
        // 双向数据绑定线路二：将dom节点上变化后的vlaue值传递给数据模型
        el.oninput = (event) => {
          vNode.context.$root[binding.expression] = event.target.value
        }
      },
      inserted() {
        console.log('inserted');
      },
      update() {
        console.log('update');
      },
      componentUpdated() {
        console.log('componentupdated');
      },
      unbind() {
        console.log('unbind');
      }
    })
    let vm = new Vue({
      el: "#app",
      data: {
        username: '张三',
        password: '123321'
      },
      methods: {

      },
      created() {

      },
      // directives: {
      //   mymodel: {
      //     bind(el, binding, vNode, oldNode) {
      //       console.log(el, binding, vNode, oldNode);
      //       console.log('bind');
      //       // 双向数据绑定线路一：将数据模型中的数据赋值给dom节点的vlaue
      //       el.value = binding.value
      //       // 双向数据绑定线路二：将dom节点上变化后的vlaue值传递给数据模型
      //       el.oninput = (event) => {
      //         vNode.context.$root[binding.expression] = event.target.value
      //       }
      //     },
      //     inserted() {
      //       console.log('inserted');
      //     },
      //     update() {
      //       console.log('update');
      //     },
      //     componentUpdated() {
      //       console.log('componentupdated');
      //     },
      //     unbind() {
      //       console.log('unbind');
      //     }
      //   }
      // }
    })
  </script>
</body>

</html>